package com.tc.msg.protocol;

import com.tc.msg.message.LoginRequestMessage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 * @Auther: tianchao
 * @Date: 2022/2/14 14:16
 * @Description:
 */
public class TestMessageCodeC {
    public static void main(String[] args) throws Exception {
        EmbeddedChannel embeddedChannel = new EmbeddedChannel(
                new LoggingHandler(LogLevel.DEBUG),
                new LengthFieldBasedFrameDecoder(1024,12,4,0,0),
                new MessageCodeCSharable()
                //new MessageCodeC()
        );
        LoginRequestMessage loginRequestMessage = new LoginRequestMessage("tianchao","123");
        //embeddedChannel.writeOutbound(loginRequestMessage);

        ByteBuf buf = ByteBufAllocator.DEFAULT.buffer();
        new MessageCodeC().encode(null,loginRequestMessage,buf);
        ByteBuf buf1 = buf.slice(0,100);
        buf1.retain();
        ByteBuf buf2 = buf.slice(100,buf.readableBytes()-100);

        embeddedChannel.writeInbound(buf1);
        // Thread.sleep(5000);
        embeddedChannel.writeInbound(buf2);
    }
}
